const Service = require("egg").Service;

class FormDataSourceService extends Service {

  async getDataPort () {
    const { app } = this;
    try {
      return await app.model.Hickey.findAll({
        include: {
          model: app.model.DataSource,
          as: 'dateSourceList',
        },

      });
    } catch (err) {
      console.log(err);
      return null;
    }
  }
  async getParamReturn (id) {
    const { app } = this;
    try {
      console.log('getParamReturn-id', id)
      return await app.model.DataSource.findOne({
        where: { id },
        include: [
          {
            model: app.model.Parameter,
            as: 'parameters',
            through: { attributes: [] }, // 排除中间表
          },
          {
            model: app.model.Return,
            as: 'returns',
            through: { attributes: [] }, // 排除中间表
          }
        ],
      });
    } catch (err) {
      console.log(err);
      return null;
    }
  }

  async getDataSource (id) {
    const { app } = this;
    try {
      console.log('getParamReturn-id', id)
      return await app.model.DataSource.findOne({
        where: { id },
        include: {
          model: app.model.Return,
          as: 'returns',
          through: { attributes: [] }, // 排除中间表
        },
      });
    } catch (err) {
      console.log(err);
      return null;
    }
  }



}

module.exports = FormDataSourceService;
